package com.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.ssm.domain.SysLog;
import com.ssm.service.ISysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
/**
 * @Author: my_code
 * @Description: 日志管理
 * @Date: Create in 17:10 2020/8/26
 */
@Controller
@RequestMapping("/syslog")
public class SysLogController {

    @Autowired
    private ISysLogService sysLogService;

    @RequestMapping("/find_All.do")
    public ModelAndView find_All(){
        ModelAndView mv = new ModelAndView();
        List<SysLog> sysLogs = sysLogService.findAllSysLog();
        mv.addObject("sysLogs",sysLogs);
        mv.setViewName("sysLog-list");
        return mv;
    }

    /**
     * @return : org.springframework.web.servlet.ModelAndView
     * @Description : 获取所有日志，并通过PageHelper.startPage(page,size)实现分页操作
     * @param : [page, size], page：页码, size：分页长度
     */
    @RequestMapping("/findAll.do")
    public ModelAndView findAll(@RequestParam(name = "page", defaultValue = "1") Integer page, @RequestParam(name = "size", defaultValue = "10") Integer size)  {
        ModelAndView mv = new ModelAndView();
        List<SysLog> sysLogList = sysLogService.findAll(page, size);
        //PageInfo就是一个分页的bean
        PageInfo pageInfo = new PageInfo(sysLogList);
        mv.addObject("pageInfo", pageInfo);
        mv.setViewName("sysLog-list");
        return mv;
    }
}
